package com.jj.core.utils;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import org.slf4j.LoggerFactory;

public class Utils {
    public static void initLog(String path) {
        String logPath = path;
        if (logPath == null) {
            logPath = "cfg/logback.xml";
        }
        LoggerContext context = (LoggerContext) LoggerFactory
                .getILoggerFactory();

        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);
            // Call context.reset() to clear any previous configuration, e.g.
            // default
            // configuration. For multi-step configuration, omit calling
            // context.reset().
            context.reset();
            configurator.doConfigure(logPath);
        } catch (JoranException je) {
            // StatusPrinter will handle this
            je.printStackTrace();
        }
        StatusPrinter.printInCaseOfErrorsOrWarnings(context);
    }
}
